/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.ui.dialogs;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.gef.commands.CommandStack;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.custom.VerifyKeyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.ClassifierTemplateParameter;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.TemplateBinding;
import org.eclipse.uml2.uml.TemplateParameter;
import org.eclipse.uml2.uml.TemplateSignature;
import org.eclipse.uml2.uml.TemplateableElement;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLPackage;

import com.cea.papyrus.classdiagram.parsers.modelgenerator.PropertyGenerator;
import com.cea.papyrus.classdiagram.parsers.texteditor.propertylabel.PropertyLabelSourceViewerConfiguration;
import com.cea.papyrus.core.commands.UMLElementCreateCommand;
import com.cea.papyrus.core.commands.template.TemplateParameterSubstitutionCreateCommand;
import com.cea.papyrus.core.editor.CommandStackUtils;
import com.cea.papyrus.core.utils.LookForElement;

/**
 * 
 */
public class PropertyLabelEditorDialog extends LabelEditorDialog {

	/**
	 * 
	 */
	final private static String TITLE = "Property";
	
	final public static int CREATE_BUTTON_ID = 3 ;
	
	// state variables to define the behavior associated to the "press create button" event
	final private int TYPE_CREATION = 0 ;
	final private int BINDING_DEFINITION = 1 ;
	private int CREATION_MODE = TYPE_CREATION ;
	
	// final private static String MESSAGE = "enter Property name";
	
	/**
	 * 
	 */
	private Property property;
	
	/**
	 * The list contains the types that are dynamically created (through the create button)
	 * For a given "dialog session", if the user the cancel button, all the types contained
	 * in the list are deleted.
	 */
	private List<Type> dynamicallyCreatedTypes;

	
	/**
	 * 
	 */
	private Document propertyLabelDocument;
	
	/**
	 * 
	 */
	private String initialValue;
	
	/**
//	 * 
//	 */
	private Menu menu;
//	
	/**
	 * 
	 */
	private List<MenuItem> menuItems;
	
	/**
	 * 
	 */
	private List<SelectionListener> selectionListeners;
	
	/**
	 * 
	 */
	private Button createButton ;

	/**
	 * 
	 */
	private BoundTypeCreationCommand boundTypeCreationCommand ;
	
	/**
	 * 
	 * 
	 * @param parentShell 
	 * @param property 
	 * @param initialValue 
	 */
	public PropertyLabelEditorDialog(Shell parentShell, Property property, String initialValue) {
		super(parentShell, TITLE, initialValue, new PropertyLabelValidator(property));
		this.property = property;
		this.value = initialValue;
		this.initialValue = initialValue; // used in case of cancel
		this.dynamicallyCreatedTypes = new ArrayList<Type>() ;
		this.boundTypeCreationCommand = null ;
	}
	
	/*
     * (non-Javadoc) Method declared on Dialog.
     */
    /**
     * 
     * 
     * @param buttonId 
     */
    @Override
	protected void buttonPressed(int buttonId) {
        if (buttonId == CREATE_BUTTON_ID) {
            value = viewer.getDocument().get();
            createPressed() ;
        } 
        else if (buttonId == IDialogConstants.CANCEL_ID) {
        	value = initialValue ;
        	PropertyGenerator generator = new PropertyGenerator(property);
        	generator.parseAndModifyProperty(initialValue) ;
        	// all the types that have been created during the dialog session are deleted
        	for (Iterator<Type> i = dynamicallyCreatedTypes.iterator() ; i.hasNext() ;) {
        		Type t = i.next() ;
        		((org.eclipse.uml2.uml.Package)t.getOwner()).getPackagedElements().remove(t) ;
        		t.setPackage(null) ;
        	}
        	if (boundTypeCreationCommand != null) {
        		boundTypeCreationCommand.undo() ;
        	}
        	super.buttonPressed(buttonId);
        }
        else {
//        	String theTypeName = property.getType().getName() ;
//        	if (boundTypeCreationCommand != null) {
//        		boundTypeCreationCommand.undo() ;
//            	CommandStackUtils stack = LookForElement.getCommandStack();
//        		Assert.isNotNull(stack, "Impossible to adapt current editor into a CommandStackUtils");
//        		stack.execute(boundTypeCreationCommand);
//        		PropertyGenerator generator = new PropertyGenerator(property);
//    	    	generator.parseAndModifyProperty(getValue()) ; // the name of the type to be created
//        	}
//        	PropertyGenerator generator = new PropertyGenerator(property);
//	    	generator.parseAndModifyProperty(getValue()) ; // the name of the type to be created
        	super.buttonPressed(buttonId);
        }
    }
	
    protected void createPressed() {
    	// add an additional menu to the add Button
    	if (CREATION_MODE == TYPE_CREATION) {
    		createMenuForCreateButton();
    		menu.setVisible(true);
    	}
    	else { // CREATION_MODE == BINDING_DEFINITION
    		PropertyGenerator generator = new PropertyGenerator(property);
    		TemplateableElement template = generator.parseUnboundPropertyType(getValue()) ;
    		// Creation of the dialog box only if all the parameters are ClassifierTemplateParameters
    		boolean onlyClassifierTemplateParameters = !template.getOwnedTemplateSignature().getParameters().isEmpty() ; 
    		if (onlyClassifierTemplateParameters) {
    			for (Iterator<TemplateParameter> i = template.getOwnedTemplateSignature().getParameters().iterator() ; i.hasNext() && onlyClassifierTemplateParameters ; ) {
    				TemplateParameter t = i.next() ;
    				onlyClassifierTemplateParameters = onlyClassifierTemplateParameters && t instanceof ClassifierTemplateParameter ;
    			}
    			if (onlyClassifierTemplateParameters) {
    				final BindingAndNamespaceTreeSelectionDialog dialog = new BindingAndNamespaceTreeSelectionDialog(getShell(), LookForElement.topPackage(property), template);
    				dialog.open() ;
    				List dialogResult = dialog.getResult() ;
    				if (dialogResult != null) {
    					Package targetPackage = (Package)dialogResult.get(0) ;
    					List<BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem> bindings = new ArrayList<BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem>() ;
    					for (int i = 1 ; i<dialogResult.size() ; i++) {
    						bindings.add((BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem)dialogResult.get(i)) ;
    					}
    					if (boundTypeCreationCommand != null)
    						boundTypeCreationCommand.undo() ;
    					boundTypeCreationCommand = createBoundType(template, targetPackage, bindings) ;
    					boundTypeCreationCommand.execute();
    					String theTypeName = property.getType().getName() ;
    					// update display of property and error message
    		    		propertyLabelDocument.set(new com.cea.papyrus.umlutils.Property(property).getLabel()) ;
    		    		value = new com.cea.papyrus.umlutils.Property(property).getLabel() ;
    		    		String errorMessage ;
    		    		errorMessage = generator.parseAndValidateProperty(getValue()) ;
    		    		setErrorMessage(errorMessage) ;
    		    		theTypeName = property.getType().getName() ;
    				}
    			}
    			else {
    				MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
    						"Dynamic bound type creation",
    				"Bound type must be created manually, as the template contains parameters that are not Types.");
//  				Debug.log(IStatus.ERROR, message);
    			}
    		}
    		else {
    			MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
						"Dynamic bound type creation",
				"The template does not have any parameters.");
    		}
    	}
    }
    
    /**
	 * Adds an additional menu to the addButton. So user can choose which element to create
	 */
	private void createMenuForCreateButton() {
		menu = new Menu (createButton);
		menu.setEnabled(false) ;
		menuItems = new ArrayList<MenuItem>() ;
		selectionListeners = new ArrayList<SelectionListener>() ;
		// add an item for each metaclass that comply with the Type metaclass
		List concreteTypeMetaclasses = LookForElement.getMetaclasses(UMLPackage.eINSTANCE.getType(), false, property) ;
		for (Iterator i = concreteTypeMetaclasses.iterator() ; i.hasNext() ; ) {
			org.eclipse.uml2.uml.Type currentType = (org.eclipse.uml2.uml.Type)i.next() ;
			menu.setEnabled(true) ;
			menuItems.add(new MenuItem(menu, SWT.PUSH)) ;
			MenuItem item = menuItems.get(menuItems.size()-1) ;
			item.setText(currentType.getName()) ;
			try {
				menuItems.get(menuItems.size()-1).addSelectionListener(new CreateElementSelectionListener(Class.forName("org.eclipse.uml2.uml."+currentType.getName()))) ;
			}
			catch (Exception e) {
				e.printStackTrace() ;
			}
		}
	}
    

	
    /* (non-Javadoc)
     * @see com.cea.papyrus.core.utils.dialog.LabelEditorDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
     */
    /**
     * 
     * 
     * @param parent 
     * 
     * @return 
     */
    @Override
	protected Control createDialogArea(Composite parent) {
        Group composite = new Group(parent, SWT.RESIZE);
        composite.setText("Specification");
        GridLayout layout = new GridLayout();
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
		createButton = createButton(parent, CREATE_BUTTON_ID , "create Type", true) ;
		composite.setLayout(layout);
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
        
        Composite viewerGroup= new Composite(composite, SWT.RESIZE); 
        FillLayout viewerLayout = new FillLayout();
        viewerGroup.setLayout(viewerLayout);
        GridData data = new GridData(GridData.GRAB_HORIZONTAL
              | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
              | GridData.VERTICAL_ALIGN_CENTER);
        data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);      
        viewerGroup.setLayoutData(data);
        viewer = new SourceViewer(viewerGroup, null, SWT.BORDER | SWT.FILL_EVEN_ODD );
        
        // configure source viewer
        propertyLabelDocument = new Document();
        propertyLabelDocument.set(value);
       
       // add completion processor key listener (ctrl+space keys) 
        viewer.appendVerifyKeyListener(new PropertyLabelKeyListener(viewer));
        
        propertyLabelDocument.addDocumentListener(new DocumentListener());
        
        viewer.configure(new PropertyLabelSourceViewerConfiguration(property));
        viewer.setDocument(propertyLabelDocument);
        
        viewer.setSelectedRange(0, value.length());
        errorMessageText = new Text(composite, SWT.READ_ONLY);
        errorMessageText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
                | GridData.HORIZONTAL_ALIGN_FILL));
        errorMessageText.setBackground(errorMessageText.getDisplay()
                .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        // Set the error message text
        // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=66292
        setErrorMessage(errorMessage);

        applyDialogFont(composite);
        return composite;
    }

    private BoundTypeCreationCommand createBoundType(TemplateableElement template, Package targetPackage, List<BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem> bindings) {
    	
    	// Bound type name computation
    	String typeName = ((NamedElement)template).getName() ;
    	for (Iterator<BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem> i = bindings.iterator() ; i.hasNext() ; ) {
    		BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem item = i.next() ;
    		typeName = typeName + "_" ;
//    		typeName = typeName + ((NamedElement)item.getParameter().getParameteredElement()).getName() ;
//    		typeName = typeName + "_" ;
    		typeName = typeName + ((NamedElement)item.getActual()).getName() ;
    	}
    	
    	// Creation of the templateable element to be bound
    	TemplateableElement elementToBeBound=null ;
    	org.eclipse.gef.commands.CompoundCommand resultCommand=null;
    	Class templateClass = null ;
    	try {
    		templateClass = Class.forName("org.eclipse.uml2.uml." + template.eClass().getName()) ;
    	}
    	catch (ClassNotFoundException e) {	
    	}
    	UMLElementCreateCommand elementToBeBoundCreateCommmand = new UMLElementCreateCommand(templateClass, targetPackage) ;
//    	CommandStackUtils stack = LookForElement.getCommandStack();
//		Assert.isNotNull(stack, "Impossible to adapt current editor into a CommandStackUtils");
		elementToBeBoundCreateCommmand.execute();
		elementToBeBound = (TemplateableElement)elementToBeBoundCreateCommmand.getElement() ;
		((NamedElement)elementToBeBound).setName(typeName) ;
		
		// Creation of the bound type create command
    	BoundTypeCreationCommand creationCommand = new BoundTypeCreationCommand(template, elementToBeBound, bindings) ;
    	
//    	Type createdBoundType = creationCommand.getCreatedBoundType() ;
    	return creationCommand;
    }
    
    private class BoundTypeCreationCommand extends org.eclipse.gef.commands.CompoundCommand {
    	
    	private TemplateableElement elementToBeBound ;
    	private Package elementToBeBoundParent ;
    	private UMLElementCreateCommand templateBindingCreateCommand;
    	private org.eclipse.gef.commands.CompoundCommand parameterSubstitutionsCommands;
    	private List<BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem> bindings ;
    	private Type oldPropertyType ;
    	private TemplateSignature targetSignature ;
    	
    	public BoundTypeCreationCommand(TemplateableElement template, TemplateableElement elementToBeBound, List<BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem> bindings) {
    		super() ;
    		this.elementToBeBound = elementToBeBound ;
    		this.elementToBeBoundParent = (Package)this.elementToBeBound.getOwner() ;
    		templateBindingCreateCommand = new UMLElementCreateCommand(org.eclipse.uml2.uml.TemplateBinding.class, elementToBeBound) ;
    		parameterSubstitutionsCommands = new org.eclipse.gef.commands.CompoundCommand() ;
    		this.oldPropertyType = property.getType() ;
    		this.bindings = bindings ;
    		this.targetSignature = template.getOwnedTemplateSignature() ;
    	}

		@Override
		public void execute() {
			// TODO Auto-generated method stub
			elementToBeBoundParent.getPackagedElements().add((PackageableElement)elementToBeBound) ;
			((Type)elementToBeBound).setPackage(elementToBeBoundParent) ;
			property.setType((Type)elementToBeBound) ;
			String theTypeName = property.getType().getName() ;
			templateBindingCreateCommand.execute() ;
			TemplateBinding createdBinding = (TemplateBinding)templateBindingCreateCommand.getElement() ;
			createdBinding.setSignature(targetSignature) ;
			for (Iterator<BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem> i = bindings.iterator() ; i.hasNext() ; ) {
				BindingAndNamespaceTreeSelectionDialog.TemplateParameterTableItem item = i.next() ;
				TemplateParameterSubstitutionCreateCommand tPSCcommand ;
				tPSCcommand = new TemplateParameterSubstitutionCreateCommand(org.eclipse.uml2.uml.TemplateParameterSubstitution.class,
						createdBinding,
						item.getParameter(),
						(TemplateableElement)item.getActual()) ;
				tPSCcommand.execute() ;
				this.add(tPSCcommand) ;
			}
		}

		@Override
		public void undo() {
			// TODO Auto-generated method stub
			super.undo();
			this.templateBindingCreateCommand.undo() ;
			this.elementToBeBoundParent.getPackagedElements().remove(elementToBeBound) ;
			((Type)this.elementToBeBound).setPackage(null) ;
			property.setType(oldPropertyType) ;
		}

		@Override
		public void redo() {
			// TODO Auto-generated method stub
			this.elementToBeBoundParent.getPackagedElements().add((PackageableElement)elementToBeBound) ;
			((Type)this.elementToBeBound).setPackage(elementToBeBoundParent) ;
			this.templateBindingCreateCommand.redo() ;
			property.setType((Type)elementToBeBound) ;
			super.redo();
		}
    	

    	
    }
    
    /**
     * Sets or clears the error message.
     * If not <code>null</code>, the OK button is disabled.
     * 
     * @param errorMessage the error message, or <code>null</code> to clear
     * 
     * @since 3.0
     */
    public void setErrorMessage(String errorMessage) {
//    	this.errorMessage = errorMessage;
//    	if ((errorMessageText != null) && !errorMessageText.isDisposed()) {
//    		errorMessageText.setText(errorMessage == null ? "" : errorMessage); //$NON-NLS-1$
//    		errorMessageText.getParent().update();
//    		// Access the ok button by id, in case clients have overridden button creation.
//    		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=113643
//    		Control button = getButton(IDialogConstants.OK_ID);
//    		if (button != null) {
//    			button.setEnabled(errorMessage == null);
//    		}
//    	}
    	super.setErrorMessage(errorMessage) ;
    	Control button = getButton(CREATE_BUTTON_ID);
		if (button != null) { 
			if (errorMessage == null) {
				button.setEnabled(false);
			}
			else if (errorMessage.startsWith("Type")) {
				button.setEnabled(true);
				CREATION_MODE = TYPE_CREATION ;
			}
			else if (errorMessage.startsWith("Parameters")) {
				button.setEnabled(true) ;
				CREATION_MODE = BINDING_DEFINITION ;
			}
			else {
				button.setEnabled(false);
			}
    	}
    }

    
    /**
     * 
     */
    private class PropertyLabelKeyListener implements VerifyKeyListener {
        
        /**
         * 
         */
        SourceViewer viewer;
        
        /**
         * Default constructor.
         * 
         * @param viewer 
         */
        public PropertyLabelKeyListener(SourceViewer viewer) {
            this.viewer = viewer;
        }
        
        /* (non-Javadoc)
         * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
         */
        /**
         * 
         * 
         * @param event 
         */
        public void verifyKey(VerifyEvent event) {
            if ((event.stateMask == SWT.CTRL) && (event.character == ' ')) {
            	if (viewer.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS)) {
                    viewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
                }
                event.doit = false;
            } else if(event.character == SWT.CR) {
                event.doit=false;
            } 
        }
    }
    
    /**
     * 
     */
    private class DocumentListener implements IDocumentListener {

		/**
		 * 
		 * 
		 * @param event 
		 */
		public void documentAboutToBeChanged(DocumentEvent event) {
		}

		/**
		 * 
		 * 
		 * @param event 
		 */
		public void documentChanged(DocumentEvent event) {
			validateInput();
		}
    	
    }
    
    /**
	 * Listener for the menu items.
	 */
	public class CreateElementSelectionListener implements SelectionListener {

		/**
		 * 
		 */
		public Class concreteTypeMetaclass;
						
		public CreateElementSelectionListener(Class concreteTypeMetaclass) {
			this.concreteTypeMetaclass = concreteTypeMetaclass ;
		}
		
		/* (non-Javadoc)
		 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
		 */
		/**
		 * 
		 * 
		 * @param e 
		 */
		public void widgetDefaultSelected(SelectionEvent e) {
		}

		/* (non-Javadoc)
		 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
		 */
		/**
		 * 
		 * 
		 * @param e 
		 */
		public void widgetSelected(SelectionEvent e) {
			setReturnCode(CREATE_BUTTON_ID) ;
	    	final int[] result = {IDialogConstants.CANCEL_ID};
	    	// Retrieves the name of the type to be created
	    	PropertyGenerator generator = new PropertyGenerator(property);
	    	String typeName = generator.parseUndefinedPropertyType(getValue()) ; // the name of the type to be created
	    	
	    	// Creation of the dialog box
	    	final NamespaceTreeSelectionDialog dialog = new NamespaceTreeSelectionDialog(getShell(), LookForElement.topPackage(property), typeName, concreteTypeMetaclass.getSimpleName());

	    	if (typeName != null) { 

	    		// open dialog window
	    		BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
	    			public void run() {
	    				result[0] = dialog.open();
	    			}
	    		});

	    		// if ok was pressed, and a package was selected
	    		// A type T with name = typeName will be created in the package
	    		// the type of the property will be set to T
	    		if(IDialogConstants.OK_ID == result[0]){
	    			org.eclipse.uml2.uml.Package selectedPackage = dialog.getResult(); 
	    			if(selectedPackage!= null){
//	    				com.cea.utils.Package utilPackage = new com.cea.utils.Package(selectedPackage) ;
//	    				com.cea.utils.Class createdType = utilPackage.createOwnedClass(typeName, VisibilityKind.PUBLIC) ;
//	    				property.setType(createdType.getUml2Class()) ;
	    				UMLElementCreateCommand command ;
	    				CommandStack stack = CommandStackUtils.getCommandStack();
	    				command = new UMLElementCreateCommand(concreteTypeMetaclass, selectedPackage) ;
	    				Assert.isNotNull(stack, "Impossible to adapt current editor into a CommandStackUtils");
	    				stack.execute(command);
	    				((Type)command.getElement()).setName(typeName) ;
	    				property.setType((Type)command.getElement()) ;
	    				dynamicallyCreatedTypes.add((Type)command.getElement()) ;
	    			}
	    		}

	    		// update display of property and error message
	    		propertyLabelDocument.set(new com.cea.papyrus.umlutils.Property(property).getLabel()) ;
	    		value = new com.cea.papyrus.umlutils.Property(property).getLabel() ;
	    		String errorMessage ;
	    		errorMessage = generator.parseAndValidateProperty(getValue()) ;
	    		setErrorMessage(errorMessage) ;
	    	}
		}
	}

    
}
